<template>
  <div>
    <Add @confirmSend="confirmSend" :optionsType="optionsType" :optionsAge="optionsAge"></Add>
  </div>
</template>
<script>
import Add from '@/views/read/addOrEditcmp'
import { chooseBookAge, chooseBookType, createUpdateCourse } from "@/api/operation";
import { ERR_OK } from "@/api/config";
import{Message} from 'element-ui'
export default {
  data() {
    return{
      optionsType: [],
      optionsAge: []
    }
  },
  methods: {
    confirmSend(params) {
      console.log(params)
      this._createUpdateCourse(params)
    },
    _createUpdateCourse(params) {
      createUpdateCourse(params)
        .then((res) => {
          if (res.code == ERR_OK) {
            // console.log(res)
            Message({
              message: '添加成功!',
              type: 'info'
            })
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    _chooseBookAge() {
      chooseBookAge()
        .then(res => {
          if (res.code == ERR_OK) {
            // console.log(res);
            this.optionsAge = res.data;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    _chooseBookType() {
      chooseBookType()
        .then(res => {
          if (res.code == ERR_OK) {
            // console.log(res);
            this.optionsType = res.data
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  },
  created() {
    this._chooseBookAge();
    this._chooseBookType();
  },
  components: {
    Add
  }
}
</script>
<style lang="scss" scoped>

</style>